#ifndef _DEFINES_H_
#define _DEFINES_H_

#include "strlib.h"
#include "ff.h"
#include "malloc.h"
//#define test // env: x86_64 linux gcc

#define preMemSize 262144
//#define preMemSize 10000
#define Data_OFFSET 1000
typedef struct {
    u32 size; //length of http Doc, bytes
    char *content; // http Doc content
} message;

typedef struct {
    u32 size;   // filesize, bytes
    u8 *data; // file data
} file;

typedef struct {
    u8 isParameter; // if is Parameter, rRate/dRate is valid, else dataLength/dataBody is valid
    u8 rRate;
    u8 dRate;
    u8 error; // if error, all is not valid
    u32 dataLength; // number of coords, sizeof dataBody is dataLength*4 bytes
    u16 *dataBody; // coords data, listed as [x,y,x,y,....]
} info;

#define root "0:"// tmp
#define indexPage "rulerPage.html"
#define page404 "<div style=\"padding:48px;\"><div style=\"word-break:break-word;font-weight:600;font-size:36px;\">404 Not Found</div></div>"

// outside ================================//
#ifdef test
    #include <stdio.h>
    #include <malloc.h>
    #define mmalloc(size) malloc(size)
    #define mfree(pointer) free(pointer)
    #define FIL FILE
    #define f_open(readStream, filename, FA_READ)  readStream = fopen(filename, "rb")
    #define getFileSize(fileSize, readStream) fseek(readStream, 0, SEEK_END); *fileSize = ftell(readStream); rewind(readStream)
    #define f_read(readStream, fileBuffer, fileSize, status) fileBuffer = (u8 *)mmalloc(fileSize); *status = fread(fileBuffer, 1, fileSize, readStream)
    #define f_close(readStream) fclose(readStream)
#else
    #define mmalloc(size) Mem_malloc(1,size)
    #define mfree(pointer) Mem_free(1,pointer)
//    #define getFileSize(fileSize, readStream) fileSize = readStream.fsize;
#endif

char *sendFile(char *response, char *reqURL);
char *getPost(char *response, u32 postLength, char *postBody, info *inf);
message *procReq(message *request, message *response, info *inf);
file readFile(char *filename);
message *preRequest(message *request);
info *preInfo(info *data);

#endif

